import asyncio_redis
import aiohttp
import async_timeout
import ujson
from config import REDIS_SERVER, REDIS_SERVER_TOKEN

def single_instance(cls, *args, **kw):
    """
    A decorator to guaranteed a class only init once
    """
    instances = {}

    def _singleton(*args, **kw):
        if cls not in instances:
            instances[cls] = cls(*args, **kw)
        return instances[cls]
    return _singleton

async def get_redis():
    connect = await asyncio_redis.Pool.create(
        host=REDIS_SERVER, 
        password=REDIS_SERVER_TOKEN
    )
    return connect

